/**
 * 微信下单js
 */

$(function() {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {
			height : $(window).height() - 56
		});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url : '../../sys/worder/list?_' + $.now(),
		height : $(window).height() - 56,
		queryParams : function(params) {
			params.name = vm.keyword;
			return params;
		},
		columns : [ {
			checkbox : true
		}, {
			field : "createTime",
			title : "创建时间",
			width : "100px"
		},{
			field : "type",
			title : "订单类型",
			width : "60px",
			align : "center",
			formatter : function(value, row, index) {
				//1 用户 2 回收员 3 扫码
				if (value == 1) {
					return '<span>用户订单</span>';
				}else if (value == 2) {
					return '<span>回收员订单</span>';
				}else {
					return '<span>扫码订单</span>';
				}
			}
		},{
			field : "userContacts",
			title : "发单人",
			width : "100px"
		}, {
			field : "userTelephone",
			title : "发单人电话",
			width : "100px"
		},{
			field : "receiptContacts",
			title : "接单人",
			width : "100px"
		},{
			field : "receiptTelephone",
			title : "接单人电话",
			width : "100px"
		}, {
			field : "orderNumber",
			title : "订单编号",
			width : "100px"
		}, {
			field : "pickTime",
			title : "取件时间",
			width : "100px"
		}, {
			field : "province",
			title : "省",
			width : "100px"
		},{
			field : "address",
			title : "详细地址",
			width : "100px"
		},{
			field : "status",
			title : "用户类型",
			width : "60px",
			align : "center",
			formatter : function(value, row, index) {
				if (value == 1) {
					return '<span>进行中</span>';
				}else if (value == 2) {
					return '<span>已完成</span>';
				}else {
					return '<span>已取消</span>';
				}
			}
		}]
	})
}

var vm = new Vue({
	el : '#dpLTE',
	data : {
		keyword : null
	},
	methods : {
		load : function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save : function() {
			dialogOpen({
				title : '新增微信下单',
				url : 'base/worder/add.html?_' + $.now(),
				width : '420px',
				height : '550px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if (checkedRow(ck)) {
				dialogOpen({
					title : '编辑微信下单',
					url : 'base/worder/edit.html?_' + $.now(),
					width : '420px',
					height : '550px',
					success : function(iframeId) {
						top.frames[iframeId].vm.wOrder.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes : function(iframeId) {
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
			if (checkedArray(ck)) {
				$.each(ck, function(idx, item) {
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url : '../../sys/worder/remove?_' + $.now(),
					param : ids,
					success : function(data) {
						vm.load();
					}
				});
			}
		}
	}
})